<?php

namespace App\Http\Controllers;

use App\Models\{
    User,
    Role,
    Permission,
};
use App\Http\Resources\UserCollection;

final class DashboardController extends Controller
{
    public function index()
    {
        return view('dashboard', [
            'users' => User::all(),
            'roles' => Role::all(),
            'permissions' => Permission::all(),
        ]);
    }

    public function userSearch($name)
    {
        return new UserCollection(User::where('user_full_name', 'LIKE', '%' . $name . '%')->with('roles')->orderBy('user_id', 'ASC')->get());
    }
}
